Thread: end of file found before }

  1. #1
    Registered User
    Join Date
    Sep 2012
    Posts
    8

    end of file found before }

    Ive looked over my program 100 times and i can not find way i have this error.
    Please HELP
    Code:
    
    #include
    
    
    "stdafx.h"
    
    #include
    <windows.h>
    
    #include
    <stddef.h>
    
    #include
    <stdlib.h>
    
    #include
    <conio.h>
    
    #include
    <stdio.h>
    
    
    int
     stack[5],top=-1,value,i,stop=0;
    
    
    void
     push(int value)
    
    {
    
        
    if(top=4)
    
        { 
    
            printf(
    "Stack is full or overflow had happend\n Please understand you may only fill the stack up to a certain limit");
    
        }
    
        
    else {
    
        top=top+1;
    
        stack[top]=value;
    
            }
    
    }
    
    void
     pop()
    
    {
    
        
    if(top==-1)
    
        { 
    
                printf(
    "Stack is empty and you need to Push a number into it");
    
        }
    
                
    else {
    
                        top=top-1;
    
                        stack[top]=value;
    
                     }
    
    }
    
    void
     show()
    
    {
    
        
    for(i=0;1<=top;i++)
    
        {
    
                    printf(
    "\nThe numbers you have entered within the stack\n,%a[i]");
    
        }
    
    }
    
    int
     main()
    
    {
    
        
    int pick,value;
    
        
    while(stop==1){
    
        printf(
    "\n1.Push:");
    
        printf(
    "\n2.POP:");
    
        printf(
    "\n0.Exit:");
    
        printf(
    "\n3.Results:");
    
        printf(
    "\nEnter your choice:");
    
        
    
    
        
    if(pick==1)
    
        {
    
                printf(
    "\nEnter value to be incerted:");
    
                scanf_s(
    "%d",value);
    
                push(value);
    
        }
    
    
        
    if(pick==2)
    
        {
    
                pop();
    
        }
    
        
    if(pick==3)
    
        {
    
                show();
    
        }
    
        
    if(pick==0)
    
        {
    
                printf(
    "\nThank you for using Dan's Push and Pop programing\n GOOD BYE ");    
    
                exit(0);
    
        }
    
                
    return 0;    
    
        }
    

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Indent your code properly and you're likely to find out the mistake yourself
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Sep 2012
    Posts
    8
    Sorry the cut and paste made it look funny

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Right. I indented your code and found the mistake, just as I thought it would be. Indent the code, please. I don't care what you say about the cut and paste: you did not format your code properly, hence the mistake is not obvious to you.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Sep 2012
    Posts
    8
    I have looked at each brace and it all is perfect. I dont have a clue why i keep getting this error. Its hard to paste into this.....for some reason. It makes it look differnt

  6. #6
    Registered User
    Join Date
    Sep 2012
    Posts
    8
    I guess i wasnt not trained in the right way to indent. Thank you for you're help. I hope i find it soon.

  7. #7
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by rockodan34
    I have looked at each brace and it all is perfect.
    Here's your program, indented properly:
    Code:
    #include "stdafx.h"
    
    #include <windows.h>
    #include <stddef.h>
    #include <stdlib.h>
    #include <conio.h>
    #include <stdio.h>
    
    int stack[5], top = -1, value, i, stop = 0;
    
    void push(int value)
    {
        if (top = 4)
        {
            printf("Stack is full or overflow had happend\n Please understand you may only fill the stack up to a certain limit");
        }
        else
        {
            top = top + 1;
            stack[top] = value;
        }
    }
    
    void pop()
    {
        if (top == -1)
        {
            printf("Stack is empty and you need to Push a number into it");
        }
        else
        {
            top = top - 1;
            stack[top] = value;
        }
    }
    
    void show()
    {
        for (i = 0; 1 <= top; i++)
        {
            printf("\nThe numbers you have entered within the stack\n,%a[i]");
        }
    }
    
    int main()
    {
        int pick, value;
    
        while (stop == 1)
        {
            printf("\n1.Push:");
            printf("\n2.POP:");
            printf("\n0.Exit:");
            printf("\n3.Results:");
            printf("\nEnter your choice:");
    
            if (pick == 1)
            {
                printf("\nEnter value to be incerted:");
                scanf_s("%d",value);
    
                push(value);
            }
    
            if (pick == 2)
            {
                pop();
            }
    
            if (pick == 3)
            {
                show();
            }
    
            if (pick == 0)
            {
                printf("\nThank you for using Dan's Push and Pop programing\n GOOD BYE ");
                exit(0);
            }
    
            return 0;
        }
    Where's the closing brace of the main function?

    Also, = is not the same as ==, so be careful. You should avoid global variables.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  8. #8
    Registered User
    Join Date
    Sep 2012
    Posts
    8
    I thought i had it indented in a proper way but as i can see youre correct way. I saw the mistake in one second. Thank you so very much.
    Also thank you for the other hints.
    You are the best

  9. #9
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    Basically, every time you use braces, indent your code.

    Code:
    int main(void)
    {
        ....
        if (banana != delicious)
        {
            if (apple != delicious)
            {
                if (pear != delicious)
                {
                    you = fussy;
                }
            }
        }
    
    
        return 0;
    }
    Fact - Beethoven wrote his first symphony in C

  10. #10
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    1. Get a smarter code editor - one which will automatically insert a closing brace, parenthesis or whatever, when you type the corresponding opener.

    2. Learn to do the above yourself.
    Eg.
    Code:
    void foo ( ) {
      for ( i = 0 ; i < 10 ; i++ ) {
        printf("hello");
      }
    }
    Is written as
    Code:
    void foo ( ) {
    }
    Then move the cursor up a line
    Code:
    void foo ( ) {
      for ( i = 0 ; i < 10 ; i++ ) {
      }
    }
    Then move the cursor up a line
    Code:
    void foo ( ) {
      for ( i = 0 ; i < 10 ; i++ ) {
        printf("hello");
      }
    }
    It might seem like a bit of extra work, but if you're 30 lines down and 4 levels deep when you get interrupted, you're just going to forget how many closing braces you need and at what point in the code.

    Another advantage is that
    Code:
    void foo ( ) {
      for ( i = 0 ; i < 10 ; i++ ) {
      }
    }
    can be compiled and tested, whereas
    Code:
    void foo ( ) {
      for ( i = 0 ; i < 10 ; i++ ) {
        printf("hello");
    is thoroughly broken.


    Coupled with some indentation rules, you'll end up with easy to read code, and you'll NEVER have to play the "hunt the missing ...." game again.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File not found exception
    By Alexandre in forum C# Programming
    Replies: 4
    Last Post: 10-03-2011, 06:02 PM
  2. Need Help: end of file found before....
    By kamitsuna in forum C++ Programming
    Replies: 5
    Last Post: 02-24-2010, 02:23 PM
  3. Symbol file not found for *.ko
    By yanglei_fage in forum Linux Programming
    Replies: 3
    Last Post: 03-30-2009, 08:48 AM
  4. unexpected end of file found
    By eam in forum C++ Programming
    Replies: 5
    Last Post: 11-06-2003, 06:10 PM
  5. how do u fix unecpected end of file found???
    By mattyans in forum C Programming
    Replies: 4
    Last Post: 03-19-2002, 09:04 PM